;(function(window) {
    var ndeduSecondary = {};
    /*二级页面侧边栏*/
    ndeduSecondary.btnSidebar = function() {
        var _navLi = $('.side-nav').find('.nav-li'),
            _mainContent = $('.main-content-each');

        _navLi.on('click', function() {
            var index = $(this).index();

            $(this).addClass('active')
                .siblings('li').removeClass('active');

            _mainContent.eq(index).addClass('active')
                .siblings(_mainContent).removeClass('active');
        })
    },
    /*展开详情按钮*/
    ndeduSecondary.btnMore = function() {
        var _content = $('.content'),
            _itemTitle = _content.find('.item-title'),
            _contentText = _content.find('.content-text');

        _itemTitle.on('click', function() {
            var articleId = $(this).attr('articleId'),
                contontText = $(this).parent().find('.content-text');
            if (contontText.css('display') == 'none') {
                createLog(articleId);
            } else {
                console.log(articleId);
            }
            if (contontText.length) {
                $(this).find('.btn-more').toggleClass('active');
                contontText.slideToggle();
            }
            
        })

        function createLog(articleId) {
            $.ajax({
                method: 'get',
                url: '/api/article/setArticleLog?articleId=' + articleId,
                dataType: 'json'
            })
        }
    },
    /*在当前页面加载新闻详情页*/
    ndeduSecondary.newsLoad = function() {
        var _content = $('.content'),
            _itemTitle = _content.find('.item-title'),
            _contentText = _content.find('.content-text'),
            articleId = $(this).attr('articleId');

        _itemTitle.on('click', function() {
            var aHref = $(this).attr('newsurl'),
                address = aHref + ' .info-content';


            if ($(this).parent(_content).find('.info-content').length) {
            } else {
                $(this).parent(_content).find(_contentText).load(address);
            }
        })
    },
    /*二级页面没有列表时，显示暂无内容提示*/
    ndeduSecondary.nonews = function() {
        var _mainContentEach = $('.main-content-each');

        _mainContentEach.each(function() {
            if ($(this).find('.content-text').length) {
            } else {
                $(this).find('.nonews').fadeIn();
            }
        });
    },
    window.ndeduSecondary = ndeduSecondary;
})(window);
$(function() {
    ndeduSecondary.btnMore();
    ndeduSecondary.btnSidebar();
    // ndeduSecondary.newsLoad();
    ndeduSecondary.nonews();
});
